{extend name="../../common/view/admin_base"/}

{block name="main"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <button class="layui-btn layui-btn-warm">字段管理</button>
            <div class="layui-btn-group layui-form">
                {if key_exists('admin/field/add',$btns)}
                {assign name="btn" value="$btns['admin/field/add']" /}
                <a class="layui-btn" href="{:url($btn['action'])}?formid={$formid}"><i class="{$btn['icon']}"></i>{$btn['name']}</a>
                {/if}
            </div>
            <table class="layui-table layui-form" id="table" lay-filter="datatable" lay-size="sm"></table>
        </div>
    </div>
</div>

<script type="text/html" id="ck_issystem">
    <input type="checkbox" disabled name="close" lay-skin="switch" lay-text="是|否" {{ d.issystem == 1 ? 'checked' : '' }} >
</script>
<script type="text/html" id="ck_ismain">
    <input type="checkbox" disabled name="close" lay-skin="switch" lay-text="是|否" {{ d.ismain == 1 ? 'checked' : '' }} >
</script>

<script type="text/html" id="actionTpl">
    {if isset($btns['admin/field/edit']) }
    {assign name="btn" value="$btns['admin/field/edit']" /}
    <a class="layui-btn layui-btn-xs" href="{:url($btn['action'])}?fieldid={{d.guid}}"><i class="{$btn['icon']}"></i>{$btn['name']}</a>
    {/if}
    {if isset($btns['admin/field/remove']) }
    {assign name="btn" value="$btns['admin/field/remove']" /}
    <a class="layui-btn layui-btn-xs removebtn" data-href="{:url($btn['action'])}?fieldid={{d.guid}}"><i class="{$btn['icon']}"></i>{$btn['name']}</a>
    {/if}

</script>

<script>
    layui.use(['table','element','form','laytpl'], function(){
        var table = layui.table;
        var form = layui.form;
        var laytpl = layui.laytpl;
        var element = layui.element;

        table.render({
            elem: '#table'
            ,url:document.URL
            ,cellMinWidth: 80
            ,cols: [[
                {type:'numbers'}
                ,{field:'name', title:'字段',width:140}
                ,{field:'title', title:'名称',width:140}
                ,{field:'type', title:'类型',width:140}
                ,{field:'ismain', title:'主表字段',width:90,templet:"#ck_ismain"}
                ,{field:'sort', title:'排序',width:120}
                ,{field:'action', title:'操作',templet: '#actionTpl', unresize: true}
            ]]
            ,page: false
            ,response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": 200,
                    "msg": res.msg,
                    "data": res.data
                };
            }
            ,done: function(res, curr, count){
                form.render();
                $.bindactions();
            }
        });

        $.bindactions = function(){
            $(".removebtn").on('click',function(){
                var url = $(this).data('href');
                top.layer.confirm("确定删除吗？此操作不能撤销！", {icon: 3, title:'提示'},
                    function(index){
                        top.layer.closeAll();
                        $.post(url,function(res){
                            layer.msg(res.msg,{
                                offset: '15px'
                                ,icon: 1
                                ,time: 1000
                            },function(){
                                document.location.reload();
                            });
                        });
                    },function (index) {
                        top.layer.close(index);
                    }
                );
            });
        }

    });
</script>
{/block}